class receiverExchange{
    constructor(connect,queueName,exchangeName,typeName,routingKey){
       this.queueName=queueName;
       this.exchangeName=exchangeName;
       this.typeName=typeName;
       this.routingKey=routingKey;
       const self=this;
       this.connect=connect;
       this.channel=this.connect.createChannel({
            json:true
       });

    //    this.channel.addSetup((channels)=>{
    //         Promise.all([
    //         channels.assertQueue(self.queueName),
    //         channels.assertExchange(self.exchangeName,self.typeName,{durable:false}),
    //         channels.bindQueue(self.queueName,self.exchangeName,this.routingKey),
    //         channels.consume(self.queueName,(data)=>{
    //             var message = JSON.parse(data.content.toString());
    //             console.log("receiver: get message", message);
    //             channels.ack(data);
    //             //func(this.channel,data)
    //         })
    //     ]);
    //    });
       //,{noAck:true}
       this.channel.waitForConnect()
        .then(function() {
            console.log("Listening for messages");
        });
    }
    // async createChannel(){
    //    const self=this;
    //    this.channel.addSetup(function(channels){
    //         //返回绑定队列的channel 
    //         console.log('创建channel',self.queueName);
    //         return Promise.all([
    //             channels.assertQueue(self.queueName),
    //             channels.assertExchange(self.exchangeName,self.typeName,{durable:false}),
    //             channels.bindQueue(self.exchangeName,self.typeName, this.routingKey),
    //             channels.consume(self.queue_name,self.consumeMes,{noAck:true})
    //         ]) ;
    //     });
       
        
    // }   
    consumeMes(data){
        var message = JSON.parse(data.content.toString());
        console.log("receiver: get message", message);
        //func(this.channel,data)
    }
}
module.exports=receiverExchange;